//////////////////////////////////////////////////////////////////////////
//	File			:	"CGameProfiler.cpp"
//
//	Author			:	Steven Seufert (SMS) and Jeremy DeSha (DS)
//	Last Modified	:	January 21, 2012 (SMS)
//
//	Purpose			:	to implement the singleton to handle all saving and loading for Spell Slingers
///////////////////////////////////////////////////////////////////////////
#include "CGameProfiler.h"
#include "CGame.h"

///////////////////////////////////////////////////
//	Function	:	"SaveUserSettings"
//	
//	Last Modified:	January 21, 2012 (SMS)
//
//	Input		:	fileName	-	the name of the file you would like to save as a string
//										
//	Return		:	none
//
//	Purpose		:	Saves the settings from the Options menu to a text file
//////////////////////////////////////////////////
void CGameProfiler::SaveUserSettings(string fileName)
{
	string path = "saves/" + fileName;
	ofstream fout;
	fout.open(path);
	if (fout.good() )
	{
		fout << CGame::GetInstance()->GetSFXVolume() << "\n";
		fout << CGame::GetInstance()->GetMusicVolume() << "\n";
		fout << CGame::GetInstance()->GetPanVolume() << "\n";
		fout << CGame::GetInstance()->GetStartingLives() << "\n";
		fout << CGame::GetInstance()->GetIsWindowed();
	}
	else
	
	fout.close();
}

///////////////////////////////////////////////////
//	Function	:	"LoadUserSettings"
//	
//	Last Modified:	January 21, 2012 (SMS)
//
//	Input		:	fileName	-	the name of the file you would like to load as a string
//										
//	Return		:	true if successfully opened the file, false if not
//
//	Purpose		:	loads the Options menu settings from a text file
//////////////////////////////////////////////////
bool CGameProfiler::LoadUserSettings(string fileName)
{
	string path = "saves/" + fileName;

	float sfxVolume = 0.5f;
	float musicVolume = 0.3f;
	float panVolume = 0;
	int startingLives = 1;
	bool isWindowed = false;

	ifstream fin;
	fin.open(path);
	if (fin.is_open() )
	{
		fin >> sfxVolume;
		fin.ignore (INT_MAX, '\n');

		fin >> musicVolume;
		fin.ignore (INT_MAX, '\n');

		fin >> panVolume;
		fin.ignore (INT_MAX, '\n');

		fin >> startingLives;
		fin.ignore (INT_MAX, '\n');

		fin >> isWindowed;
		//fin.ignore (INT_MAX, '\n');
	}
	else
	{
		char szBuffer[256] = {0};
		sprintf_s(szBuffer, _countof(szBuffer), "Failed to load the user settings for the Options menu using %s", fileName); 
		MessageBox(0, szBuffer, "GameProfiler Error", MB_OK);
		// use default settings and return
		return false;
	}
	
	fin.close();

	

	CGame::GetInstance()->SetSFXVolume(sfxVolume);

	sfxVolume = CGame::GetInstance()->GetSFXVolume();

	CGame::GetInstance()->SetMusicVolume(musicVolume);
	CGame::GetInstance()->SetPanVolume(panVolume);
	CGame::GetInstance()->SetStartingLives(startingLives); 
	CGame::GetInstance()->SetIsWindowed(isWindowed);

	// success
	return true;
}

///////////////////////////////////////////////////
//	Function	:	"SaveGameFile"
//	
//	Last Modified:	
//
//	Input		:	fileName	-	the name of the file you would like to save as a string
//										
//	Return		:	none
//
//	Purpose		:	Saves all the data for a game file 
//////////////////////////////////////////////////
void CGameProfiler::SaveGameFile(string fileName)
{

}

///////////////////////////////////////////////////
//	Function	:	"LoadGameFile"
//	
//	Last Modified:	
//
//	Input		:	fileName	-	the name of the file you would like to load as a string
//										
//	Return		:	none
//
//	Purpose		:	loads all the data for a game file 
//////////////////////////////////////////////////
void CGameProfiler::LoadGameFile(string fileName)
{

}
